package com.huang.dao.impl;

import com.huang.dao.UserDao;
import com.huang.mapper.UserMapper;
import com.huang.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
@Slf4j
public class UserDaoImpl implements UserDao {

/*    private static Map<Integer, User> users = null;

    private static Integer id = 100004;

    static {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        users = new LinkedHashMap<>();
        try {
            users.put(1001, new User(1001, "admin", "123456", 1, "303913473@qq.com", sdf.parse("2000-01-01")));
            users.put(1002, new User(1002, "master", "1111", 2, "403913473@qq.com", sdf.parse("2000-01-02")));
        } catch (ParseException e) {
            log.error(e.getMessage());
        }
    }

    public Collection getAllUsers() {
        return users.values();
    }

    public User getUserById(Integer id) {
        return users.get(id);
    }

    public String saveUser(User user) {
        user.setId(id++);
        users.put(id, user);
        return "ok";
    }*/

    @Resource
    UserMapper userMapper;

    @Override
    public List<User> getAllUsers(){
       return userMapper.getAllUsers();
    }

    @Override
    public User getUserById(Integer id){
        return userMapper.getUserById(id);
    }

    @Override
    public int saveUser(User user){
        return userMapper.saveUser(user);
    }

    @Override
    public int deleteUser(Integer id){
        return userMapper.deleteUser(id);
    }
}
